<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // https://leetcode-cn.com/problems/valid-anagram/
        // 简单 map 解决
        var isAnagram = function(s, t) {
            let sArr = s.split('');
            let tArr = t.split('');
            let map = new Map();
            for (let i = 0; i < sArr.length; i++) {
                if (map.has(sArr[i])) {
                    let count = map.get(sArr[i]);
                    map.set(sArr[i], count + 1);
                } else {
                    map.set(sArr[i], 1);
                }
            }
            for (let i = 0; i < tArr.length; i++) {
                if (map.has(tArr[i])) {
                    let count = map.get(tArr[i]);
                    map.set(tArr[i], count - 1);
                } else {
                    map.set(tArr[i], 1);
                }
            }

            return !Array.from(map.values()).some(item => {
                return item > 0;
            })
        };
        console.log(isAnagram('anagram', 'nagaram'))
    </script>
</body>
</html>